package com.sky.com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@Mapper
public interface AddressBookMapper {
    // 条件查询
    List<AddressBook> getList(AddressBook addressBook);


    //根据id查询
    @Select("select * from addres_book where id =#{id}")
    AddressBook getById(Long id);

    // 修改地址
    void updateById(AddressBook addressBook);

    //根据id删除
    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);

    // 根据用户id修改 是否为默认地址
    @Update("update address_book set is_default = #{isDefault} whre user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);

    @Update("update addredd_book set is_default = 0 where user_id = #{id}")
    void addNotDefault(Long userId);

    @Update("update address_book set is_default =1 where user_id =#{id}")
    void setDefault(Long id);

    //当前登录用户收货地址列表
    @Select("select * from address_book where user_id=#{uid}")
    List<AddressBook> list(Long uid);

    //新增收货地址
    void insert(AddressBook addressBook);

    //设置当前用户地址都是非默认
    @Update("update address_book set is_default=0 where user_id=#{userId}")
    void setNotDefault(Long userId);

    //设置为默认收货地址
    @Update("update address_book set is_default =1 where id=#{id}")
    void updateDefault(Long id);

    //查询默认 收货地址
    @Select("select * from address_book where user_id=#{uid} and is_default=1")
    AddressBook getDefaultAddress(Long uid);


}
